package uml.behavioral.mediator;

import java.util.HashSet;

/**
 * 中介者--抽象中介者<br>
 * on 2023/1/2 22:25
 */
public abstract class Mediator {
    private String name;//群聊名称
    private User msgSender;//信息发送者
    protected HashSet<User> users;//群聊人员-抽象同事集合

    private Mediator() {
        users = new HashSet<>();
    }

    public Mediator(String name) {
        this();
        this.name = name;
        System.out.println("系统消息："+name+"群聊创建成功");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public User getMsgSender() {
        return msgSender;
    }

    public void setMsgSender(User msgSender) {
        this.msgSender = msgSender;
    }

    public HashSet<User> getUsers() {
        return users;
    }

    /**
     * 将用户user加入群聊
     * @param user
     */
    public void join(User user) {
        users.add(user);
    }
    public void quitGroup(User user){
        users.remove(user);
    }

    /**
     * 在群内发送消息
     */
    public abstract void chatInGroup();
}
